/**
 * Created by yujianfu on 2019/9/11.
 */
import React from 'react'

import {message, Form, DatePicker, Button, Select, Input, InputNumber} from 'antd'
const {RangePicker} = DatePicker
const FormItem = Form.Item
const {Option} = Select;
import {fetchPost} from '../../utils/request'
import moment from 'moment'

class MerchantInit extends React.Component {

    constructor(props) {
        super(props)
        this.state = {
            params: {},
            startDate: null,
            endDate: null,
            loanType: 1,
            agentList: [],
            isSubmitButtonDisabled: false
        }
    }

    componentDidMount() {

    }

    handleSubmit = (e) => {
        e.preventDefault()
        this.props.form.validateFields((err, fieldsValue) => {
            let merchantCode = fieldsValue["merchantCode"];
            let account = fieldsValue["account"];
            let password = fieldsValue["password"];
            let mobile = fieldsValue["mobile"];
            // let appId = fieldsValue["appId"];
            let productCategoryName = fieldsValue["productCategory"];
            let appName = fieldsValue["appName"];
            // let appCode = fieldsValue["appCode"];
            let params = {merchantCode, account, password, mobile, productCategoryName, appName};
            fetchPost('/merchant/create/Li64Edf8', params).then(json => {
                this.setState({
                    isSubmitButtonDisabled: true
                });
                if (json && json.code === 0) {
                    message.info(json.msg);
                } else {
                    message.error(json.msg);
                }
            })
        });
    }

    render() {

        const {getFieldDecorator} = this.props.form;

        const formItemLayout = {
            labelCol: {span: 5},
            wrapperCol: {span: 18},
        };

        return (
            <div style={{"width": "400", "margin": "0 auto"}}>
                <Form   {...formItemLayout} onSubmit={this.handleSubmit}>
                    <br/>
                    <br/>

                    <Form.Item {...formItemLayout} label="商户号">
                        {getFieldDecorator('merchantCode', {
                            rules: [
                                {
                                    required: true,
                                    message: '必填',
                                },
                            ],
                        })(<Input placeholder="必填"/>)}
                    </Form.Item>

                    <Form.Item {...formItemLayout} label="登陆账号">
                        {getFieldDecorator('account', {
                            rules: [
                                {
                                    required: true,
                                    message: '必填',
                                },
                            ],
                        })(<Input placeholder="必填"/>)}
                    </Form.Item>


                    <Form.Item {...formItemLayout} label="登陆密码">
                        {getFieldDecorator('password', {
                            rules: [
                                {
                                    required: true,
                                    message: '必填',
                                },
                            ],
                        })(<Input placeholder="必填"/>)}
                    </Form.Item>

                    <Form.Item {...formItemLayout} label="手机号">
                        {getFieldDecorator('mobile', {
                            rules: [
                                {
                                    required: true,
                                    message: '必填',
                                },
                            ],
                        })(<Input placeholder="必填"/>)}
                    </Form.Item>


                    {/*<Form.Item {...formItemLayout} label="AppId">*/}
                    {/*    {getFieldDecorator('appId', {*/}
                    {/*        rules: [*/}
                    {/*            {*/}
                    {/*                required: true,*/}
                    {/*                message: '必填',*/}
                    {/*            },*/}
                    {/*        ],*/}
                    {/*    })(<InputNumber placeholder="必填"/>)}*/}
                    {/*</Form.Item>*/}


                    <Form.Item {...formItemLayout} label="产品名称">
                        {getFieldDecorator('productCategory', {
                            rules: [
                                {
                                    required: true,
                                    message: '必填',
                                },
                            ],
                        })(<Input placeholder="必填"/>)}
                    </Form.Item>


                    <Form.Item {...formItemLayout} label="appName">
                        {getFieldDecorator('appName', {
                            rules: [
                                {
                                    required: true,
                                    message: '必填',
                                },
                            ],
                        })(<Input placeholder="必填"/>)}
                    </Form.Item>


                    {/*<Form.Item {...formItemLayout} label="appCode">*/}
                    {/*    {getFieldDecorator('appCode', {*/}
                    {/*        rules: [*/}
                    {/*            {*/}
                    {/*                required: true,*/}
                    {/*                message: '必填',*/}
                    {/*            },*/}
                    {/*        ],*/}
                    {/*    })(<Input placeholder="必填"/>)}*/}
                    {/*</Form.Item>*/}

                    <Form.Item wrapperCol={{span: 12, offset: 6}}>
                        <Button type="primary" disabled={this.state.isSubmitButtonDisabled} htmlType="submit">
                            Submit
                        </Button>
                    </Form.Item>
                </Form>
            </div>
        )
    }
}
const a = Form.create()(MerchantInit)
export default a

